package com.hxzy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxzy.dto.SysRoleSearchDTO;
import com.hxzy.entity.SysRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

@Mapper
public interface SysRoleMapper  extends BaseMapper<SysRole> {


    IPage<SysRole> search(IPage page, @Param(value = "dto") SysRoleSearchDTO dto);

    /**
     * 查询该角色拥有的菜单ID
     * @param roleId
     * @return
     */
    List<BigDecimal> getRoleOwnMenuId(BigDecimal roleId);

    /**
     * 为角色分配菜单权限  SYS_ROLE_MENU表
     * @param roleId
     * @param owernMenus
     * @return
     */
    Long saveSysRoleMenu(@Param(value = "roleId") BigDecimal roleId, @Param(value = "owernMenus") BigDecimal[] owernMenus);

    /**
     * 根据ROLE_ID删除SYS_ROLE_MENU表数据
     * @param roleId
     * @return
     */
    Long deleteSysRoleMenuByRoleId(BigDecimal roleId);

    /**
     * 根据ROLE_ID和MENU_ID做删除操作
     * @param roleId
     * @param removeMenus
     * @return
     */
    Long removeSysRoleMenu(@Param(value = "roleId") BigDecimal roleId, @Param(value = "removeMenus") Set<BigDecimal> removeMenus);

    /**
     * 判断当前用户角色KEY
     * @param adminId
     * @return
     */
    @Select(value = "select s.ROLE_KEY from SYS_ROLE s inner join SYS_USER_ROLE su on s.ROLE_ID=su.ROLE_ID where su.USER_ID=#{adminId}")
    Set<String> findRoleKeyByAdminId(Long adminId);
}